/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.umss.arqui10.modelo;

/**
 *
 * @author Rho1and0
 */
public class Pair<TYPEA, TYPEB> implements Comparable< Pair<TYPEA, TYPEB> > {
  protected final TYPEA Key_;
  protected final TYPEB Value_;

  public Pair(TYPEA key, TYPEB value) {
    Key_   = key;
    Value_ = value;
  }
  public TYPEA getKey() {
    return Key_;
  }
  public TYPEB getValue() {
    return Value_;
  }
    @Override
  public String toString() {
    System.out.println("in toString()");
    StringBuilder buff = new StringBuilder();
      buff.append("Key: ");
      buff.append(Key_);
      buff.append("\tValue: ");
      buff.append(Value_);
    return(buff.toString() );
  }
  public int compareTo( Pair<TYPEA, TYPEB> p1 ) {
    System.out.println("in compareTo()");
    if ( null != p1 ) {
      if ( p1.equals(this) ) {
        return 0;
      } else if ( p1.hashCode() > this.hashCode() ) {
            return 1;
      } else if ( p1.hashCode() < this.hashCode() ) {
        return -1;
      }
    }
    return(-1);
  }
  public boolean equals( Pair<TYPEA, TYPEB> p1 ) {
    System.out.println("in equals()");
    if ( null != p1 ) {
      if ( p1.Key_.equals( this.Key_ ) && p1.Value_.equals( this.Value_ ) ) {
        return(true);
      }
    }
    return(false);
  }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Pair<TYPEA, TYPEB> other = (Pair<TYPEA, TYPEB>) obj;
        if (this.Key_ != other.Key_ && (this.Key_ == null || !this.Key_.equals(other.Key_))) {
            return false;
        }
        if (this.Value_ != other.Value_ && (this.Value_ == null || !this.Value_.equals(other.Value_))) {
            return false;
        }
        return true;
    }
    @Override
  public int hashCode() {
    int hashCode = Key_.hashCode() + (31 * Value_.hashCode());
    System.out.println("in hashCode() [" + Integer.toString(hashCode) + "]");
    return(hashCode);
  }
}

